<?php
/**
 * class App_Model_Pagination
 *
 * @author kim
 */
class App_Model_Pagination
{
    /**
     * factory of paginator
     *
     * @param array|Iterator $data - the data for pager
     * @param int $total - total records number
     * @param null|int $page - current page number
     * @param null|int $count - item count for per page
     * @return Zend_Paginator
     */
    static public function factory($data, $total, $page = null, $count = null)
    {
        // Setup default pagination control scrolling style
        Zend_Paginator::setDefaultScrollingStyle('Sliding');

        // Setup pagination control view script. See the pagation control tutorial page
        Zend_View_Helper_PaginationControl::setDefaultViewPartial('shared/pagination_control.phtml');

        // create reviews dataset
        $dataset = new App_Model_PaginationDataset($data, $total);

        // Create a Paginator
        $paginator = Zend_Paginator::factory($dataset);

        // Read the current page number and item count from the request. Default is 1 if no explicit page number is provided.
        $paginator->setCurrentPageNumber($page)
                  ->setItemCountPerPage($count)
                  //->setPageRange(3)
                  ;

        return $paginator;
    }

}